Source for file GetFoldersAndFiles.php

Documentation is available at GetFoldersAndFiles.php

  1. <?php /*
  2.  * FCKeditor - The text editor for internet
  3.  * Copyright (C) 2003-2005 Frederico Caldeira Knabben
  4.  * 
  5.  * Licensed under the terms of the GNU Lesser General Public License:
  6.  *         http://www.opensource.org/licenses/lgpl-license.php
  7.  * 
  8.  * For further information visit:
  9.  *         http://www.fckeditor.net/
  10.  * 
  11.  * File Name: GetFoldersAndFiles.php
  12.  *     Implements the GetFoldersAndFiles command, to list
  13.  *     files and folders in the current directory.
  14.  *     Output is in XML
  15.  * 
  16.  * File Authors:
  17.  *         Grant French (grant@mcpuk.net)
  18.  */
  19.     var $fckphp_config;
  20.     var $type;
  21.     var $cwd;
  22.     var $actual_cwd;
  23.     
  24.     function GetFoldersAndFiles($fckphp_config,$type,$cwd{
  25.         $this->fckphp_config=$fckphp_config;
  26.         $this->type=$type;
  27.         $this->raw_cwd=$cwd;
  28.         $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd));
  29.         $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd));
  30.     }
  31.     
  32.     function run({
  33.  
  34.         header ("Content-Type: application/xml; charset=utf-8");
  35.         echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
  36.         ?>
  37. <!DOCTYPE Connector [
  38.  
  39. <?php include "dtd/iso-lat1.ent";?>
  40.     
  41.     <!ELEMENT Connector    (CurrentFolder,Folders,Files)>
  42.         <!ATTLIST Connector command CDATA "noname">
  43.         <!ATTLIST Connector resourceType CDATA "0">
  44.         
  45.     <!ELEMENT CurrentFolder    (#PCDATA)>
  46.         <!ATTLIST CurrentFolder path CDATA "noname">
  47.         <!ATTLIST CurrentFolder url CDATA "0">
  48.         
  49.     <!ELEMENT Folders    (#PCDATA)>
  50.     
  51.     <!ELEMENT Folder    (#PCDATA)>
  52.         <!ATTLIST Folder name CDATA "noname_dir">
  53.         
  54.     <!ELEMENT Files        (#PCDATA)>
  55.         
  56.     <!ELEMENT File        (#PCDATA)>
  57.         <!ATTLIST File name CDATA "noname_file">
  58.         <!ATTLIST File size CDATA "0">
  59. ] >
  60.         
  61. <Connector command="GetFoldersAndFiles" resourceType="<?php echo $this->type?>">
  62.     <CurrentFolder path="<?php echo $this->raw_cwd?>" url="<?php echo $this->fckphp_config['urlprefix'$this->actual_cwd?>" />
  63.     <Folders>
  64. <?php
  65.             $files=array();
  66.             if ($dh=opendir($this->real_cwd)) {
  67.                 while (($filename=readdir($dh))!==false{
  68.                     
  69.                     if (($filename!=".")&&($filename!="..")) {
  70.                         if (is_dir($this->real_cwd."/$filename")) {
  71.                             //check if$fckphp_configured not to show this folder
  72.                             $hide=false;
  73.                             for($i=0;$i<sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders']);$i++
  74.                                 $hide=(ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFolders'][$i],$filename)?true:$hide);
  75.                             
  76.                             if (!$hideecho "\t\t<Folder name=\"$filename\" />\n";
  77.                             
  78.                         else {
  79.                             array_push($files,$filename);
  80.                         }
  81.                     }
  82.                 }
  83.                 closedir($dh)
  84.             }
  85.             echo "\t</Folders>\n";
  86.             echo "\t<Files>\n";
  87.  
  88.             for ($i=0;$i<sizeof($files);$i++{
  89.                 
  90.                 $lastdot=strrpos($files[$i],".");
  91.                 $ext=(($lastdot!==false)?(substr($files[$i],$lastdot+1)):"");
  92.                 
  93.                 if (in_array(strtolower($ext),$this->fckphp_config['ResourceAreas'][$this->type]['AllowedExtensions'])) {
  94.                 
  95.                     //check if$fckphp_configured not to show this file
  96.                     $editable=$hide=false;
  97.                     for($j=0;$j<sizeof($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles']);$j++
  98.                         $hide=(ereg($this->fckphp_config['ResourceAreas'][$this->type]['HideFiles'][$j],$files[$i])?true:$hide);
  99.                     
  100.                     if (!$hide{
  101.                         if ($this->fckphp_config['ResourceAreas'][$this->type]['AllowImageEditing']
  102.                             $editable=$this->isImageEditable($this->real_cwd."/".$files[$i]);
  103.                         
  104.                         echo "\t\t<File name=\"".htmlentities($files[$i])."\" size=\"".ceil(filesize($this->real_cwd."/".$files[$i])/1024)."\" editable=\"" $editable?"1":"0" "\" />\n";    
  105.                     }
  106.  
  107.                 }
  108.                 
  109.             }
  110.         
  111.             echo "\t</Files>\n"
  112.             echo "</Connector>\n";
  113.     }
  114.     
  115.     
  116.     function isImageEditable($file{
  117.         $fh=fopen($file,"r");
  118.         if ($fh{
  119.             $start4=fread($fh,4);
  120.             fclose($fh);
  121.             
  122.             $start3=substr($start4,0,3);
  123.             
  124.             if ($start4=="\x89PNG"//PNG
  125.                 return (function_exists("imagecreatefrompng"&& function_exists("imagepng"));
  126.                 
  127.             elseif ($start3=="GIF"//GIF
  128.                 return (function_exists("imagecreatefromgif"&& function_exists("imagegif"));
  129.                 
  130.             elseif ($start3=="\xFF\xD8\xFF"//JPEG
  131.                 return (function_exists("imagecreatefromjpeg")&& function_exists("imagejpeg"));
  132.                 
  133.             elseif ($start4=="hsi1"//JPEG
  134.                 return (function_exists("imagecreatefromjpeg")&& function_exists("imagejpeg"));
  135.                 
  136.             else {
  137.                 return false;
  138.             }
  139.             
  140.         else {
  141.             return false;
  142.         }
  143.     }
  144.     
  145.     
  146. }
  147.  
  148. ?>

Documentation generated on Mon, 05 May 2008 16:20:12 +0400 by phpDocumentor 1.4.0